<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<c:set var="ctx" value="${pageContext.request.contextPath}" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>供应商维护客户经理管理</title>
	<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<div tabid="tabA" title="供应商维护客户经理管理" lselected="true">
			<form id="formSet1" class="l-form">

				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">轻卡商家报单设置</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否开启轻卡商家报单</div>
						<div class="field">
							<input id="declarationYes" type="radio" value="1" name="declaration" /> 是
							<input id="declarationNo" type="radio" value="0" name="declaration" /> 否
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否开启轻卡商家测算</div>
						<div class="field">
							<input id="estimateYes" type="radio" value="1" name="estimate" /> 是
							<input id="estimateNo" type="radio" value="0" name="estimate" /> 否
						</div>
					</div>
					<div class="btnsBox">
						<span id="savePropBtn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
					</div>
				</div>

				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">征信开关及每周可查次数</span>
						<input name="splAttrCd" id="splAttrCd" type="hidden" class="ui-textbox" value="${splAttrCd }">
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否有权查询征信</div>
						<div class="field">
							<input id="isAuthCrdChkYes" type="radio" value="1" name="isAuthCrdChk" /> 是
							<input id="isAuthCrdChkNo" type="radio" value="0" name="isAuthCrdChk" /> 否
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">每周可查询征信次数</div>
						<div class="field" style="width: 100%;">
							<input name="limChkTms" id="limChkTms" type="text" class="ui-textbox" value=""
								   validate ="{number:true,required:true}"
								   <c:if test="${not empty isCheckCreditBlackList and isCheckCreditBlackList == 1}">disabled</c:if> />
						</div>
					</div>
					<!-- 2018-08-22 16:33:00 殷烈征信规则需求,暂时不上生产 -->
					<!-- <div class="fieldBox col_50">
						<div class="label">当前可查询征信总次数</div>
						<div class="field" style="width: 100%;">
							<input name="limChkTms" id="limChkTms" type="text" class="ui-textbox" value="" validate ="{number:true,required:true}">
						</div>
					</div> -->
					<!-- <div class="fieldBox col_50">
						<div class="label">是否启用征信规则</div>
						<div class="field" style="width: 100%;">
							<input  id="isEnableYES" type="radio" value="1" name="isEnable" /> 开
							<input  id="isEnableNO" type="radio" value="0" name="isEnable" /> 关
						</div>
					</div> -->
					
					<!-- <div class="fieldBox col_50">
						<div class="label">前置征信活体开关</div>
						<div class="field">
							<input  id="livSwitchYES" type="radio" value="1" name="livSwitch" /> 开
							<input  id="livSwitchNO" type="radio" value="0" name="livSwitch" /> 关
						</div>
					</div>

					<div class="fieldBox col_50">
						<div class="label">前置征信授权书开关</div>
						<div class="field">
							<input  id="crdLoaSwitchYES" type="radio" value="1" name="crdLoaSwitch" /> 开
							<input  id="crdLoaSwitchNO" type="radio" value="0" name="crdLoaSwitch" /> 关
						</div>
					</div> -->
					<div class="btnsBox">
						<c:if test="${empty isCheckCreditBlackList or isCheckCreditBlackList == 0}">
							<span id="saveCiCfgBtn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
						</c:if>
					</div>
				</div>
				

				
				<div class="sqPanel">
					<div class="sqPanel_head inL">
						<div class="btnsBox inLC">
							<span id="spl_rl_add_btn" class="sq-button sq-button-round" onclick="splRlAddBtnEvent();">添加</span>
						</div>
						<span>维护客户经理信息</span>
					</div>
					<div class="sqPanel_body">
						<div id="ligergrid_A1" class="sq-grid"></div>
					</div>
				</div>
				<!-- <div class="btnsBox">
					<span id="saveBtn1" class="sq-button sq-button-round">保存</span>
				</div> -->
			</form>
		</div>
		<div tabid="tabB" title="商家APP登录用户管理" id="tabBId">
			<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
		</div>
		<c:if test="${isVip == 1}">
            <div tabid="tabC" title="金诚业务系统登录用户管理" id="tabCId">
                <iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
            </div>
        </c:if>
	</div>
</div>
<div  style="display:none">
	<div id= "configDilog" >
		<div class="fieldset1 tabel_col tabel_col_1 clearFix">
			<div class="fieldBox col_100_auto">
				<div class="label">事业部</div>
				<div class="field">
					<input  id="buOrgNml" type="text" class="ui-textbox" value="">
				</div>
			</div>
			<div class="fieldBox col_100_auto">
				<div class="label">管理员</div>
				<div class="field">
					<input type="text" id="cstMgrNm" name="cstMgrNm" ltype="combobox" placeholder="请选择"/>
					<input id="mgrId" style="display:none" type="text" class="ui-textbox" value="">
				</div>
				<input id="tel" type="text" style="display:none" class="ui-textbox" value="" validate="{required:true,mobile:true}">
			</div>
		</div>

	</div>
</div>

<script type="text/javascript">
	var configDialog=null,
			npSocialRlGrid=null,
			searchOrgTree=null,
			mgrManager=null,
			COMBO_GRID1=null,//配置
			buOrgCd=null,//客户经理所属事业部
			org_Cd=null, //客户经理所属组织架构

			splId='${splId}',
			splNm='${splNm}',
			usrIds =${usrIds}
			splBizTypCdList =${splBizTypCdList}
			isPrivateTypCdList = ${isPrivateTypCdList}
			buOrgCdList = [];
			var isCheckCreditBlackList = '${isCheckCreditBlackList}';

	var pageInApp={
		flag:true
	}; // to 下一级子窗口 接口
	var pageInTab=null;
	var loadedTabs=[]
	$(function(){
		initTab();

		if ($('#savePropBtn')) {
			$('#savePropBtn').css("background-image", "-webkit-linear-gradient(top, #999, #999)");
		}
		if ($('#saveCiCfgBtn')) {
			$('#saveCiCfgBtn').css("background-image", "-webkit-linear-gradient(top, #999, #999)");
		}

        //保存轻卡商家配置
        /*$('#savePropBtn').click(function(){
			$("#readRlBtn").attr("disabled", "disabled");
            var form = liger.get("formSet1");
            var data = form.getData();
            data.splId = splId;
            data.splNm = splNm;
            var url = '<%=path%>/spl/splpropinfo/saveSplPropInfo.do';
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:data,
                url: url,
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });*/

		//保存查征信配置
		/*$('#saveCiCfgBtn').click(function(){
			var form = liger.get("formSet1");
			/!* if (!form.valid()) {
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
				return ; //验证不通过，不执行以下代码
			} *!/
			var data = form.getData();
			data.splId = splId;
			data.splNm = splNm;
			//console.log(data);
			var url = '<%=path%>/spl/splcicfg/saveCiCfg1.do';
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: url,
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						//npSocialRlGrid.setParm("splId",splId);
						//npSocialRlGrid.reload();
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		});*/

		$("#saveBtn1").click(function(event) {
			var form = liger.get("formSet1");
			/* if (!form.valid()) {
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
				return false; //验证不通过，不执行以下代码
			} */
			var data = form.getData();
			data["mgrListJSON"] = JSON.stringify(npSocialRlGrid.getData());
			data["splId"]= splId;
			//alert(JSON.stringify(data["mgrListJSON"]));
			var gridData = eval("(" + data["mgrListJSON"] + ")");
//			alert(JSON.stringify(gridData));
			var str = [];
			for(var i = 0; i < gridData.length; i++){
				if(!gridData[i].isPrivate){
					str.push(gridData[i].rlNm);
				}
			}
			if(str && str.length > 0){
				$.ligerDialog.SQalert({content: "管理员：["+ str+"]私海状态没有设置，请重新设置！" , SQ_type: "warning" });
				return ;
			}
			data.isAuthCrdChk = $('input[name="isAuthCrdChk"]:checked ').val();
			data.livSwitch = $('input[name="livSwitch"]:checked ').val();
			data.crdLoaSwitch = $('input[name="crdLoaSwitch"]:checked ').val();
			//alert(JSON.stringify(data));return;
			var url = '<%=path%>/product/splUsrR/addModify.do';
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: url,
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						npSocialRlGrid.setParm("splId",splId);
						npSocialRlGrid.reload();
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		});
		COMBO_GRID1 =$("#cstMgrNm").ligerComboBox({

			selectBoxWidth: 350,
			selectBoxHeight: 240,
			valueFieldID: 'mp',
			valueField: 'id',
			textField: 'refRlNm',
			grid: {
				columns: [
					{ display: '员工姓名', name: 'refRlNm', minWidth: 300 }
				],

				switchPageSizeApplyComboBox: false,
				url : '<%=path%>/system/sysUsr/getUsrByOrgId.do?isDataAuth=0',
				method: 'get',
				root:'rows',
				record:'total',
				pageSize: 10,
				cssClass: "SMALL_grid",
				checkbox: false,
				frozen: false,
				onAfterShowData: function (currentData) {
				}
			},
			delayLoadGrid: true, //点击的时候出发
			onChangeValue: function (value) {
				/*  if (COMBO_GRID1) {
				 if (value=="") comboGrid_defaultValue = ""; //如果点击清空'x'，就滞空初始值
				 };
				 SetIframe_height();*/
			},

			/* 		isShowCheckBox: false, isMultiSelect: false,
			 initIsTriggerEvent: false,
			 data: {},
			 valueFieldID: 'mp',
			 valueField: 'id',//客户id
			 textField:'refRlNm',//真实姓名 */
			onSelected : function(value,text){
				//alert('-------UsrId:'+value+'==refRlNm:'+text);//可以用TODO
				$('#mgrId').val(value);
			}


		});
		
		$('#isEnableYES').click(function(){
			document.getElementById("limChkTms").setAttribute("readOnly","true");
		});
		$('#isEnableNO').click(function(){
			document.getElementById("limChkTms").removeAttribute("readOnly");
		});

		COMBO_GRID1.setDisabled();//先禁用 -> 控制下拉表格COMBO_GRID1的请求，启用后点下拉框就会请求

		$('#formSet1').ligerForm({
			validate : true
		});
		initSplConfigGrid();
		initOrgTree();
		initData();

	});

	function initData(){
		//debugger;
		var id = splId;
		if(!id){
			return;
		}
		var _url = '<%=path%>/product/splInfo/getById.do';
		$.ajax({
			type: 'get',
			dataType:'json',
			data:{id:id},
			url: _url,
			success:function(msg){
				if(msg.success == 1){
					setData(msg.data);//设置数据
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			}
		});
	}
	function setData(data){
		//是否开启轻卡商家报单
		$("input[name='declaration'][value="+data.declaration+"]").prev(".l-radio").click();
		$("input[name='declaration'][value!="+data.declaration+"]").attr("disabled",true);
		//是否开启轻卡商家测算
		$("input[name='estimate'][value="+data.estimate+"]").prev(".l-radio").click();
		$("input[name='estimate'][value!="+data.estimate+"]").attr("disabled",true);
		//是否可以查询征信
		$("input[name='isAuthCrdChk'][value="+data.isAuthCrdChk+"]").prev(".l-radio").click();
		$("input[name='isAuthCrdChk'][value!="+data.isAuthCrdChk+"]").attr("disabled",true);
		if(isCheckCreditBlackList && isCheckCreditBlackList == '1'){
			//$("input[name='isAuthCrdChk']").attr("readOnly",true);
			$("input[name='isAuthCrdChk']").attr("disabled",true);

		}
		$("#limChkTms").val(data.limChkTms);
		document.getElementById("limChkTms").setAttribute("readOnly","true");
		//是否启用征信配置  殷烈-征信规则需求已搁置
		//$("input[name='isEnable'][value="+data.isEnable+"]").prev(".l-radio").click();
		//前置征信活体开关
		//if(StringUtils.isNotEmpty(data.livSwitch)){
		//	$("input[name='livSwitch'][value="+data.livSwitch+"]").prev(".l-radio").click();
		//}else{
		//	$("#livSwitchNO").prev(".l-radio").click();
		//}
		//前置征信授权书开关
		//if(StringUtils.isNotEmpty(data.crdLoaSwitch)){
		//	$("input[name='crdLoaSwitch'][value="+data.crdLoaSwitch+"]").prev(".l-radio").click();
		//}else{
		//	$("#crdLoaSwitchNO").prev(".l-radio").click();
		//}
		
		/*if (data.isEnable == 1) {
			$("#limChkTms").val(data.limChkTms);
			document.getElementById("limChkTms").setAttribute("readOnly","true");
			//$('#limChkTms').attr('readonly','readonly');
		} else {
			$("#limChkTms").val(data.limChkTms);
		}*/

		//禁用选择按钮
		//if($("[name=livSwitch]")){//特殊情况使用
		//	var obj = $("[name=livSwitch]");
		//	obj.setDisabled_ligerRadio(true);
		//};
		//if($("[name=crdLoaSwitch]")){//特殊情况使用
		//	var obj = $("[name=crdLoaSwitch]");
		//	obj.setDisabled_ligerRadio(true);
		//};
	};
	//管理员新增dialog
	function splRlAddBtnEvent(){
		if(configDialog==null){
			configDialog = $.ligerDialog.open({
				width: 600,
				height: 250,
				title: '选择管理员',
				target:$('#configDilog'),
				buttons:[{text:'添加',onclick:function(i,d){
					f_add();f_clear();d.hide();
				}},
					{text:'关闭',onclick:function(i,d){
						d.hide();
					}
					}]
			});
		}else{
			configDialog.show();
		}
	};
	function deleteDB(rowdata_id,_usrId,_id){
		//删除数据库
		var _id = _id;
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{id:_id},
				url: '<%=path%>/product/splUsrR/removeById.do',
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type:"waitting"});
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						npSocialRlGrid.reload();
						for(var i = 0; i < usrIds.length; i++){
							if(usrIds[i] == _usrId){
								usrIds.splice(i,1);
							}
						}
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		});
	}
	function deletePage(rowdata_id,_usrId){
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			//删除页面
			npSocialRlGrid.deleteRow(rowdata_id);
		})
		for(var i = 0; i < usrIds.length; i++){
			if(usrIds[i] == _usrId){
				usrIds.splice(i,1);
			}
		}
	}
	//初始化管理人员信息
	function initSplConfigGrid() {
		if(!splId){//供应商ID为空  新增供应商
			return;
		}
		npSocialRlGrid = $("#ligergrid_A1").ligerGrid({
			url: '<%=path%>/product/splUsrR/searchSplCofigInfo.do?',
			method : 'get',
			parms:{splId:splId},
			async: false,
			columns: [
				{
                    display: '业务类型', name: 'splBizTypCd', minWidth: 200,
                    valueField: 'splBizTypCd',
                    textField: 'splBizTypCdNm',
                    editor: {
                        type: 'combobox',
                        isShowCheckBox: true,
                        isMultiSelect: true,
                        data: splBizTypCdList,
                        valueField: 'key',
                        textField: 'value'
                    }
                },
				{ display: '事业部', name: 'orgDispNm', width: 300, editor: {type: 'String'}},
				{ display: '管理员', name: 'rlNm', width: 140,editor: {type: 'String'}},
				{ display: '联系方式', name: 'mp', width: 150, editor: {type: 'String'}},
				{ display: '客户经理 id', name: 'usrId', width: 150, hide: true ,editor: {type: 'String'}},
				{ display: 'id', id: 'id', width: 300, hide: true ,editor: {type: 'String'}},
				{ display: 'buOrgCd', id: 'buOrgCd', width: 300, hide: true ,editor: {type: 'String'}},// 客户经理所属事业部
				{ display: 'org_Cd', id: 'org_Cd', width: 300, hide: true ,editor: {type: 'String'}},//客户经理所属组织架构
				{ display: '设置私海状态', name: 'isPrivate', minWidth: 150,
					editor: {
						type: 'select',
						data: isPrivateTypCdList,
						valueField: 'key',
						textField: 'value'
					},
					valueField: 'isPrivate',
					textField: 'isPrivateCdNm',
					render: function (item) {
						return item.isPrivateCdNm;
					}
				},
				{ display: '操作', width: 130 , align:'left',
					render: function (rowdata, rowindex, value){
						var jsonData = JSON.stringify(rowdata);
						jsonData = jsonData.replace(/"/g,'@');
						//console.log(jsonData);
						var d='';
						d+='<input type="text" name="id" value="'+rowdata.id+'"/>';
						if(rowdata.id){
							d='<a class="sq-button-hasicon" href="javascript:deleteDB(';
							d+="'"+rowdata.__id+"'";
							d+=",'"+rowdata.usrId+"'";
							d+=",'"+rowdata.id+"'";
							d+=')"><i class="sqBtnIco_7"></i>删除</a>';
							d+='<a id="saveBtn'+rowindex+'" class="sq-button-hasicon" style="display:none;" href="javascript:saveSplUsrR(\''+jsonData+'\','+rowindex+')"><i class="sqBtnIco_10"></i>保存</a>'
						}else{
							d='<a class="sq-button-hasicon" href="javascript:deletePage(';
							d+="'"+rowdata.__id+"'";
							d+=",'"+rowdata.usrId+"'";
							d+=')"><i class="sqBtnIco_7"></i>删除</a>';
							d+='<a id="saveBtn'+rowindex+'" class="sq-button-hasicon" href="javascript:saveSplUsrR(\''+jsonData+'\','+rowindex+')"><i class="sqBtnIco_10"></i>保存</a>'
						}
						return d;
					}
				}
			],
			pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height: 300,
			heightDiff: -2,
			enabledEdit: true,
	        isScroll: false,
	        checkbox:false,
	        rownumbers:true,
	        allowUnSelectRow: true,
			alternatingRow: false,
			enabledSort:false,
			onAfterShowData: function() {
				SetIframe_height ();
			},
	        onRenderComplete: function () {
	        	iframeResize ();
	        },
	        onSelectRow: function (rowdata, rowid, rowobj) {
	        	isEditable(rowdata.refIsSysDef);
	        },
	        onSuccess: function (data, grid) {
	        },
			onAfterEdit : function(editParm){
				//console.log(editParm);
				// 验证是否只有一位私海关系的客户经理
				/*if (editParm.text == '是') {
					//console.log('yes');
					var dataList = npSocialRlGrid.getData();
					console.log(dataList);
					//debugger;
					var count = 0;
					console.log(buOrgCdList);
					for(data in dataList){
						//console.log(data);//data是下标
						if(dataList[data].isPrivateCdNm == '是'){
							var _buOrgCd = editParm.record.buOrgCd.substring(0,8);
							if ($.inArray(_buOrgCd, buOrgCdList) >= 0) {
								if (_buOrgCd == dataList[data].buOrgCd.substring(0,8)) {
									count += 1;
								}
							}
						}
					}
					if(count > 1){
						$.ligerDialog.SQalert({content:"私海客户经理有且仅有一个！请重新赋予私海权限！", SQ_type: "error"});
						count = 0 ;
						npSocialRlGrid.reload();
						return ;
					}else{
						count = 0;
					}
				}*/
				$('#saveBtn'+editParm.rowindex).css('display','inline-block');
			},
			onBeforeEdit : function(editParm){
				//$('#saveBtn'+editParm.rowindex).css('display','inline-block');
				var dataList = npSocialRlGrid.getData();
				buOrgCdList = [];
				for (data in dataList) {
					if(dataList[data].isPrivateCdNm == '是'){
						var _buOrgCd = dataList[data].buOrgCd.substring(0, 8);
						buOrgCdList.push(_buOrgCd);
					}
				}
			}
		});
	};
	function iframeResize () {
	    if (parent.parent.mainApp) {
	        parent.parent.mainApp.parentTab.onResize();
	    };
	};
	
	/*
	是否系统内置参数获取
	*/
	function isEditable(isSysDef){
		if(isSysDef==1){
			Editable=false;
		}else{
			Editable=true;
		}
	};
	function saveSplUsrR(jsonData, index){
		jsonData = jsonData.replace(/@/g, '"');
		var rowdata = JSON.parse(jsonData);
		npSocialRlGrid.submitEdit(rowdata);
		//return;
		//console.log(jsonData);
		//console.log(rowdata);
		var form = liger.get("formSet1");
		//if (!form.valid()) {
		//	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
		//	return ; //验证不通过，不执行以下代码
		//}
		var data = form.getData();
		//console.log(JSON.stringify(data));
		//data["mgrListJSON"] = JSON.stringify(npSocialRlGrid.getData());
		data["mgrListJSON"] = '['+jsonData+']';
		data["splId"]= splId;
		
		//alert(JSON.stringify(data["mgrListJSON"]));
		var gridData = eval("(" + data["mgrListJSON"] + ")");
		//console.log(JSON.stringify(gridData));
		var str = [];
		for(var i = 0; i < gridData.length; i++){
			if(!gridData[i].isPrivate){
				str.push(gridData[i].rlNm);
			}
			if(rowdata.isPrivate != gridData[i].isPrivate){
				str.push(gridData[i].rlNm);
			}
		}
		// 校验私海状态是否设置
		//if(str && str.length > 0){
		//	$.ligerDialog.SQalert({content: "管理员：["+ str+"]私海状态没有设置，请重新设置！" , SQ_type: "warning" });
		//	return ;
		//}
		
		data.isAuthCrdChk = $('input[name="isAuthCrdChk"]:checked ').val();

		data.livSwitch = $('input[name="livSwitch"]:checked ').val();
		data.crdLoaSwitch = $('input[name="crdLoaSwitch"]:checked ').val();
		//console.log(JSON.stringify(data));
		//return;
		var url = '<%=path%>/product/splUsrR/addOrModifySplUsrR.do';
		var wait_dialog;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:data,
			url: url,
			beforeSend: function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					npSocialRlGrid.setParm("splId",splId);
					npSocialRlGrid.reload();
					//$('#limChkTms').val('');
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			}
		});
	}
	
	function initOrgTree(){
		//debugger;
		var params = {};
		params.cstMgrOrgCd = '${currOrg}';
		searchOrgTree = $("#buOrgNml").ligerComboBox({
			width: 350,
			selectBoxWidth: 350,
			selectBoxHeight: 150,
			//限制只能选叶节点，父节点不能点击
			treeLeafOnly: false,
			textField:"tName",
            valueField:"tCode",
			showTreePath: true,
			tree: {
				ajaxType: 'get',
				textFieldName:"tName",
                idFieldName:"tCode",
				checkbox: false,
				parentIcon: "none",
				childIcon: "none",
				needCancel : false,
				single : true
			},
			onSelected : function(value,text){
				//debugger;
				var a=searchOrgTree.treeManager.getDataByID(value)
				searchMgrNmList(a.id);
				buOrgCd=value;//客户经理所属事业部
				org_Cd=a.id; //客户经理所属组织架构
			}
		});
		<%-- url: '<%=path%>/project/prjbscinfo/searchBuOrgTree.do', --%>
		$.ajax({
			type: 'get',
			dataType:'json',
			data: params,
			url: '<%=path%>/customer/cstbscinfo/initOrgTree.do',
			success:function(msg){
				//if(msg.success == 1){
					//debugger;
					searchOrgTree.treeManager.setData(msg);
					searchOrgTree.clear();
				//}else{
				//	$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				//}
			}
		});
	}
	function f_add(){
		if(buOrgCd != null && buOrgCd.length > 8){
		//debugger;
		if(null == $('#mgrId').val() || "" == $('#mgrId').val()){
			$.ligerDialog.SQalert({content: "请选择管理员！" ,SQ_type: "warning" });
		}else{
			var flag = 0;
			for(var i = 0; i < usrIds.length; i++){
				if(usrIds[i] == $('#mgrId').val()){
					flag = 1;
				}
			}
			if(flag == 0){
				var row = npSocialRlGrid.getRow(0);
				npSocialRlGrid.addRow({
					splBizTypCd: "",
					orgDispNm: $('#buOrgNml').val(),
					rlNm: $('#cstMgrNm').val(),
					mp: $('#tel').val(),
					usrId : $('#mgrId').val(),
					buOrgCd:buOrgCd, //客户经理所属事业部
					org_Cd:org_Cd,//客户经理所属组织架构
					id:""
				},row,true);
				usrIds.push($('#mgrId').val());
			}else{
				$.ligerDialog.SQalert({content: "与该用户已存在业务，请勿重复添加!" ,SQ_type: "warning" });
			}
		}
		}else{
			$.ligerDialog.SQalert({content: "请配置到具体分公司下!" ,SQ_type: "warning" });
		}
	}
	function f_clear(){
		$('#splBizTypCd').val('');
		//var buOrgNmlObj = liger.get("buOrgNml");
		//buOrgNmlObj.setValue(" ");
		var cstMgrIdObj = liger.get("cstMgrNm");
		cstMgrIdObj.selectValue(" ");
		$('#tel').val('');
		$('#mgrId').val('');
	}
	function searchMgrNmList(orgId){
		COMBO_GRID1.setEnabled();//启用//先禁用 -> 控制下拉表格COMBO_GRID1的请求，启用后点下拉框就会请求
		$(COMBO_GRID1.element).click();
		//debugger;
		var paramData = {"orgId":orgId};
		liger.get('cstMgrNm').gridManager.setParm('orgId',orgId);
		liger.get('cstMgrNm').gridManager.reload();




		//alert(JSON.stringify(paramData));
		<%-- 	var _url = '<%=path%>/system/sysUsr/getUsrByOrgId.do';
            $.ajax({
                type: 'get',
                dataType: 'json',
                data: paramData,
                url: _url,
                success: function (msg) {
                    //alert(JSON.stringify(msg.rows));
                    $("#cstMgrNm").ligerGetComboBoxManager().setData(msg.rows);
                    var cstMgrIdObj = liger.get("cstMgrNm");
                    cstMgrIdObj.selectValue(" ");
                }
            }); --%>

	}

	//初始化Tab
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			onBeforeSelectTabItem: function (tabid) {
				if(tabid!="tabA"){

				}
			},
			onAfterSelectTabItem: function(tabid) {
				if (loadedTabs.indexOf(tabid)<0) {
					loadedTabs.push(tabid);
					switch (tabid){
						case "tabB":
							pageInTab.setTabItemSrc(tabid, "<%=path%>/system/sysUsr/toSplUsrListPage.do?splId="+splId+'&splNm='+splNm);
							break;
						case "tabC":
							pageInTab.setTabItemSrc(tabid, "<%=path%>/system/sysUsr/toJCSplUsrListPage.do?splId="+splId+'&splNm='+splNm);
							break;
					}
				};
				SetIframe_height();
			}
		});

		$.extend(true, pageInApp, {
			pageInTab: pageInTab
		});
	};
</script>
</body>
</html>
